package com.horoscope.astrology.zodiac.signs.free

import android.content.Context
import android.content.pm.PackageManager

/**
 * 获取AndroidManifest中的 mata-data 数据
 * */
object AppMetaDataParser {

    fun getHostIP(context: Context): String = getMetaValue(context, META_DATA_NAME_HOST_IP)

    fun getChannel(context: Context): String = getMetaValue(context, META_DATA_NAME_CHANNEL)

    fun getPayKey(context: Context): String = getMetaValue(context, META_DATA_PAY_KEY)

    private const val META_DATA_NAME_HOST_IP = "HOST_IP"
    private const val META_DATA_NAME_CHANNEL = "CHANNEL"
    private const val META_DATA_PAY_KEY = "GOOGLE_PAY_IN_APP_KEY"

    private fun getMetaValue(context: Context, key: String): String {
        val packageManager = context.packageManager
        val appInfo =
            packageManager.getApplicationInfo(context.packageName, PackageManager.GET_META_DATA)
        return appInfo.metaData[key] as String
    }

}